﻿using System;
using System.Collections.Generic;
using System.Text;
using TSVNAddin.SVN;
using System.IO;

namespace TSVNAddin.Core
{
	public class PathAddedAction
	{
		private readonly IVersionControl _VersionControl;
		private readonly IFileStorage _FileStorage;

		public PathAddedAction(IVersionControl versionControl, IFileStorage fileStorage)
		{
			_VersionControl = versionControl;
			_FileStorage = fileStorage;
		}

		public virtual void Execute(string path)
		{
			RemoveExistingSVNFolder(path);
			_VersionControl.Add(path);
		}

		private void RemoveExistingSVNFolder(string path)
		{
			if (!path.EndsWith("\\"))
				return;

			var svnPath = Path.Combine(path, ".svn");
			_FileStorage.DeleteDirectory(svnPath);
		}
	}
}
